package md.mru.core.repositories;

import md.mru.core.domains.administration.TreeModelUserGroup;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author sergiu.marin
 * @since 16.04.2014.
 */
public interface TreeModelUserGroupRepository extends JpaRepository<TreeModelUserGroup, Long> {

    @Query("SELECT t FROM TreeModelUserGroup t WHERE t.id.userGroup.id=:groupId")
    public List<TreeModelUserGroup> getTreeModelUserGroups(@Param(value = "groupId") Long groupId);

    @Modifying
    @Query("DELETE FROM TreeModelUserGroup t WHERE t.id.userGroup.id=:groupId")
    void deleteByGroupId(@Param(value = "groupId") long groupId);
}
